//
//  DestinationTableViewCell.m
//  hai游～
//
//  Created by jakf_17 on 15/5/21.
//  Copyright (c) 2015年 jakf_17. All rights reserved.
//

#import "DestinationTableViewCell.h"
#import "DestinaImageView.h"
@implementation DestinationTableViewCell


- (void)dealloc
{
    [_leftUpImage release];
    [_leftDownImage release];
    [_rightUpImage release];
    [_rightDownImage release];
    [super dealloc];
    
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.array = [NSMutableArray array];
        [self setSelectionStyle:UITableViewCellSelectionStyleNone];
    }
    return self;
}
- (void)createMyCellWithArray:(NSArray *)array
{
    [self.array addObjectsFromArray:array];
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];

    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    if (array.count >= 1) {
        self.leftUpImage = [[DestinaImageView alloc] init];
        [_leftUpImage addGestureRecognizer:tap1];
        [self.contentView addSubview:_leftUpImage];
        [_leftUpImage release];
        _leftUpImage.frame = CGRectMake(10, 0, ([[UIScreen mainScreen] bounds].size.width - 30) / 2, ([[UIScreen mainScreen] bounds].size.width - 30) / 2);
        if (array.count >= 2) {
            
      
            self.rightUpImage = [[DestinaImageView alloc] init];
            [_rightUpImage addGestureRecognizer:tap5];
            [self.contentView addSubview:_rightUpImage];
            [_rightUpImage release];
            _rightUpImage.frame = CGRectMake(([[UIScreen mainScreen] bounds].size.width - 30) / 2 + 20, 0, ([[UIScreen mainScreen] bounds].size.width - 30) / 2, ([[UIScreen mainScreen] bounds].size.width - 30) / 2);
            if (array.count >= 3) {
                
            
                self.leftDownImage = [[DestinaImageView alloc] init];
                [_leftDownImage addGestureRecognizer:tap3];
                [self.contentView addSubview:_leftDownImage];
                [_leftDownImage release];
                _leftDownImage.frame = CGRectMake(10, ([[UIScreen mainScreen] bounds].size.width - 30) / 2 + 10, ([[UIScreen mainScreen] bounds].size.width - 30) / 2, ([[UIScreen mainScreen] bounds].size.width - 30) / 2);
                if (array.count >= 4) {
                    
                
                    self.rightDownImage = [[DestinaImageView alloc] init];
                    [_rightDownImage addGestureRecognizer:tap4];
                    
                    [self.contentView addSubview:_rightDownImage];
                    [_rightDownImage release];
                    _rightDownImage.frame = CGRectMake(([[UIScreen mainScreen] bounds].size.width - 30) / 2 + 20, ([[UIScreen mainScreen] bounds].size.width - 30) / 2 + 10, ([[UIScreen mainScreen] bounds].size.width - 30) / 2, ([[UIScreen mainScreen] bounds].size.width - 30) / 2);
                }
            }
        }
    }
    [tap1 release];
    [tap5 release];
    [tap3 release];
    [tap4 release];
}

- (void)tapAction:(UITapGestureRecognizer *)sender
{
    DestinaImageView *imageView = (DestinaImageView *)sender.view;
    self.block(imageView.model);
}

- (void)layoutSubviews
{
//    if (_array.count >= 2) {
//        self.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, ([[UIScreen mainScreen] bounds].size.width - 30) + 10 + 5);
//    }
//    self.frame = CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width , ([[UIScreen mainScreen] bounds].size.width - 30) + 5);
    [super layoutSubviews];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
